Page({
  data: {
    active: 0,
    sbArr: []
  },
  onLoad() {
    this.getArr(1)
  },
  onChange(event) {
    console.log(event.detail.name)
    if (event.detail.name == 0) {
      this.getArr(1)
    } else if (event.detail.name == 1) {
      this.getArr(2)
    } else {
      this.getArr(3)
    }
  },
  // 获取数据
  getArr(e) {
    let openid = wx.getStorageSync('openid').openid
    let arr = [];
    wx.request({
      method: "POST",
      url: `https://watermark.czmao.cn:3000/examine/?openid=${openid}&state=${e}`,
      success: (res) => {

        for (let i = 0; i < res.data.list.length; i++) {
          arr.unshift(res.data.list[i])
        }
        // console.log(arr)
        let separatedMap = new Map();

        arr.forEach(obj => {
          if (!separatedMap.has(obj.img_number)) {
            separatedMap.set(obj.img_number, []);
          }
          separatedMap.get(obj.img_number).push(obj);
        });
        let sb = []
        // 输出每个编号对应的对象数组  
        for (let [img_number, objArray] of separatedMap) {
          // console.log(img_number, objArray);
          sb.push({ img_number: objArray })
        }
        console.log(sb)
        this.setData({
          sbArr: sb
        })
        console.log(this.data.sbArr.length)
      }
    })
  },
  toSC() {
    wx.navigateTo({
      url: '../../pages/upload_index/upload_index',
    })
  },
  toIndex() {
    wx.navigateBack({
      delta: 1,
      fail: (err) => {
        wx.switchTab({
          url: '../../pages/index/index',
        })
      }
    })
  }

});